package entity

import (
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//CompAccoDivi 对公存款认定分户情况
type CompAccoDivi struct {
	ID   int        `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	ACID int        `gorm:"column:ACID"` //帐户序号
	EMID int        `gorm:"column:EMID"` //员工序号
	EMNO string     `gorm:"column:EMNO"` //员工工号
	EMNM string     `gorm:"column:EMNM"` //员工名称
	DSDT time.Time  `gorm:"column:DSDT"` //分户日期
	WODT *time.Time `gorm:"column:WODT"` //销户日期
	DPNM string     `gorm:"column:DPNM"` //所属部门
	DSVL float64    `gorm:"column:DSVL"` //分户值
	ISWO bool       `gorm:"column:ISWO"` //是否删除
	SQDT *time.Time `gorm:"-"`           //申请日期
}

//TableName 对公存款认定分户情况
func (CompAccoDivi) TableName() string {
	return "V_COMP_ACCO_DIVI"
}

// AfterFind 查询后触发器
func (c *CompAccoDivi) AfterFind(tx *gorm.DB) (err error) {
	sqlStr := `select max("SQDT") SQDT from
	(select "SQDT" from "T_COMP_CLIE_DIVI_HIS" where "ACID" =? and "EMID1" =? and "SQDT">=?
	union all
	select "SQDT" from "T_COMP_CLIE_DIVI2_HIS"  where "ACID" =? and "EMID1" =? and "SQDT">=?) T`
	base.MYDB.Raw(sqlStr, c.ACID, c.EMID, c.DSDT, c.ACID, c.EMID, c.DSDT).Scan(&c.SQDT)
	return
}

func CompAccoDiviEF() base.EntityFunc {
	return func() interface{} {
		entity := CompAccoDivi{}
		return &entity
	}
}
func CompAccoDiviESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CompAccoDivi
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("CompAccoDivi", base.NewDefaultDao(CompAccoDiviEF(), CompAccoDiviESF(), nil, "my"))
}
